#include "Particle.h"

int round ( float f ) 
{
	return (int)floorf(f + 0.5f);
}

LAB::LAB_TYPE deltaE( LAB lab1, LAB lab2 )
{
	LAB::LAB_TYPE deltaL2 = lab1.l - lab2.l; deltaL2 *= deltaL2;
	LAB::LAB_TYPE deltaA2 = lab1.a - lab2.a; deltaA2 *= deltaA2;
	LAB::LAB_TYPE deltaB2 = lab1.b - lab2.b; deltaB2 *= deltaB2;

	return sqrtf(deltaL2 + deltaA2 + deltaB2);
}

HSL::HSL_TYPE deltaHUE( HSL hsl1, HSL hsl2 )
{
	return deltaHUE(hsl1.h, hsl2.h);
}

HSL::HSL_TYPE deltaHUE( HSL::HSL_TYPE hue1, HSL::HSL_TYPE hue2 ) 
{

	HSL::HSL_TYPE d = abs(hue1 - hue2);
	if (d > 0.5f) {
		HSL::HSL_TYPE m = min(hue1, hue2) + 1;
		HSL::HSL_TYPE M = max(hue1, hue2);
		d = m - M;
	}

	return d;
}